﻿///@author Rafał Hazan
///@email  rafal.hazan@gmail.com
#include "MatrixGraph.h"

const unsigned int MatrixGraph::MAX_NUMBER_VERT = 100000;
const unsigned int MatrixGraph::MAX_NUMBER_EDGE = 500000;
const unsigned int MatrixGraph::MAX_EDGE_WEIGHT = 1000000000;

std::ostream & operator<<(std::ostream & output, const MatrixGraph & m) {
	output << "Matrice [" << std::endl;
	for(::std::vector<MatrixGraph::vec_v>::const_iterator iter = m._graphMatrix.begin(); iter != m._graphMatrix.end(); ++iter)
	{
		output << "[ ";
		for(MatrixGraph::vec_v::const_iterator i2 = iter->begin(); i2 != iter->end(); ++i2)
		{
			output << *i2 << ", ";
		}
		output << " ]" << std::endl;
	}
	output << "] Matrice." << std::endl;
    return output;
}

MatrixGraph::MatrixGraph(unsigned int vSize)
	: _edgesQuantity(0), _vertQuantity(vSize)
{
	_graphMatrix = ::std::vector<vec_v>(vSize, ::std::vector<V>((vSize), 0));
}

MatrixGraph::~MatrixGraph()
    throw()
{
}

void MatrixGraph::setEdge(int row, int column, V val)
{
	if (_graphMatrix[row][column] == 0 && val != 0)
	{
		++_edgesQuantity;
	}
	else if (_graphMatrix[row][column] != 0 && val == 0)
	{
		--_edgesQuantity;
	}
	_graphMatrix[column][row] = _graphMatrix[row][column] = val;
}

void MatrixGraph::print()
{
	std::cout << "Wczytany graf" << std::endl;
	for(std::vector<vec_v>::const_iterator rowIter = _graphMatrix.begin(); rowIter != _graphMatrix.end(); ++rowIter)
	{
		for(std::vector<V>::const_iterator columnIter = rowIter->begin(); columnIter != rowIter->end(); ++columnIter)
		{
			std::cout << " " << *columnIter;
		}
		std::cout << std::endl;
	}
}

unsigned int MatrixGraph::getVSize() const
{
	return _vertQuantity;
}

unsigned int MatrixGraph::getESize() const
{
	return _edgesQuantity;
}

bool MatrixGraph::areConnectedVerts(int v1, int v2) const
{
	return _graphMatrix[v1][v2] != 0;
}